package com.handu.luna.core.domain.promotion;

import java.math.BigDecimal;

import javax.persistence.Entity;
import javax.persistence.Transient;

import com.handu.luna.core.domain.goods.Goods;

@Entity
public class SecKillGroupBuyGoods extends Promotion {
	private int secKillGroupBuyId;
	private long goodsId;
	@Transient
	private Goods goods;
	private int goodsNumber;
	private BigDecimal goodsPrice;
	
	public int getSecKillGroupBuyId() {
		return secKillGroupBuyId;
	}
	public void setSecKillGroupBuyId(int secKillGroupBuyId) {
		this.secKillGroupBuyId = secKillGroupBuyId;
	}
	public long getGoodsId() {
		return goodsId;
	}
	public void setGoodsId(long goodsId) {
		this.goodsId = goodsId;
	}
	public Goods getGoods() {
		if(this.goodsId != 0 && goods == null){
			goods = context.getGoodsRepository().findOne(this.goodsId);
		}
		return goods;
	}
	public void setGoods(Goods goods) {
		this.goods = goods;
	}
	public int getGoodsNumber() {
		return goodsNumber;
	}
	public void setGoodsNumber(int goodsNumber) {
		this.goodsNumber = goodsNumber;
	}
	public BigDecimal getGoodsPrice() {
		return goodsPrice;
	}
	public void setGoodsPrice(BigDecimal goodsPrice) {
		this.goodsPrice = goodsPrice;
	}
	
	public String getSucessFlashMessage(){
		String messagePrefix = (null==this.getId() ?"添加" : "修改");
		try {
			return messagePrefix + this.getGoods().getName() + "成功。";
		} catch ( SecurityException e) {
			return messagePrefix + "成功。";
		}
	}
}
